package com.nioSocketCore.chapter01;

import java.nio.CharBuffer;

/**
 * @author : wushikai
 * <p>
 * date : 2022-04-29
 * 方 法 int remaining()的作用：返回  "当前位置"  与 limit 之间的元素数
 */
public class BufferRemaining {


    public static void main(String[] args) {


        char[] charArray = new char[]{'a', 'b', 'c', 'd', 'e'};
        CharBuffer charBuffer = CharBuffer.wrap(charArray);
        System.out.println(" A capacity () =" + charBuffer.capacity() + " limit() =" + charBuffer.limit() + "  position() = " + charBuffer.position());
        charBuffer.position(2);
        System.out.println(" B capacity () =" + charBuffer.capacity() + " limit() =" + charBuffer.limit() + "  position() = " + charBuffer.position());
        System.out.println("charBuffer.hasRemaining() = " + charBuffer.hasRemaining());
        System.out.println("charBuffer.remaining () =  " + charBuffer.remaining());
        System.out.println(charBuffer.get(0));
        System.out.println(charBuffer.get(1));

        for (int i = 0; i < charBuffer.limit(); i++) {

            System.out.print(  (char)  charBuffer.get(i)  +" ");
        }
        System.out.println();


        System.out.println(" A capacity () =" + charBuffer.capacity() + " limit() =" + charBuffer.limit() + "  position() = " + charBuffer.position());

    }


}
